#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

struct Node {
  int val;
  int ch[2];
} tr[10005];
int tot;
map<int, int> mp;

int newnode(int val) {
  ++tot;
  tr[tot].val = val;
  tr[tot].ch[0] = tr[tot].ch[1] = 0;
  return tot;
}
int build_tree() {
  int val;
  cin >> val;
  if (val == -1) return 0;
  int p = newnode(val);
  tr[p].ch[0] = build_tree();
  tr[p].ch[1] = build_tree();
  return p;
}
void dfs(int p, int x) {
  if (!p) return;
  mp[x] += tr[p].val;
  dfs(tr[p].ch[0], x - 1);
  dfs(tr[p].ch[1], x + 1);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int root, id = 0;
  while (true) {
    root = build_tree();
    if (!root) break;
    ++id;
    dfs(root, 0);
    cout << "Case " << id << ":" << endl;
    bool start = true;
    for (auto p : mp) {
      if (start)
        start = false;
      else
        cout << ' ';
      cout << p.second;
    }
    cout << endl << endl;
    tot = 0;
    mp.clear();
  }
  return 0;
}